package mju.cxf.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Random;


@Data
@NoArgsConstructor
public class Email {
    private static final Random rd=new Random();
    public  static final String from;
    static{
        from="2323686166@qq.com";
    }
    public  String subject ;
    private String text;
    private String to;
    private String code;
//    验证码
    public Email(String subject, String to, boolean codeT) {
        this.subject = subject;
        this.to = to;
        if (codeT){
            this.code=setCode();
            this.text = "<html>" +
                    "<head>" +
                    "<style>" +
                    "body { font-family: Arial, sans-serif; color: #333; padding: 20px; }" +
                    "h2 { color: #4CAF50; }" +
                    "p { line-height: 1.5; }" +
                    ".code { font-size: 18px; font-weight: bold; color: blue; text-decoration: underline; }" +
                    "</style>" +
                    "</head>" +
                    "<body>" +
                    "<h2>亲爱的用户，</h2>" +
                    "<p>感谢您使用我们的服务！</p>" +
                    "<p>您的验证码是：<span class='code'>" + this.code + "</span>。</p>" +
                    "<p>请在5分钟内输入该验证码以完成验证。</p>" +
                    "<p>如果您没有请求此验证码，请忽略此邮件。</p>" +
                    "<p>祝好！</p>" +
                    "</body>" +
                    "</html>";


        }

    }
   private String setCode(){
       String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567w9827291636292001374789";
       StringBuilder code = new StringBuilder();
       Random random = new Random();

       for (int i = 0; i < 6; i++) {
           int index = random.nextInt(characters.length());
           code.append(characters.charAt(index));
       }

       return code.toString();
   }
}
